<template>
	<view>
	<mescroll-body ref="mescrollRef" @init="mescrollInit" :down="downOption" :up="upOption" @down="downCallback"
	 @up="upCallback">
		<!--实物抽奖列表-->
		<prizelist :giftlist="giftlist"></prizelist>
	</mescroll-body>
	<!--加载遮罩-->
	<loadingpage v-if="globelloading"></loadingpage>
	</view>
</template>

<script>
	import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins.js";
	export default{
		mixins: [MescrollMixin],
		data(){
			return {
				globelloading: true,
				giftlist:[],
				downOption:{
					auto:true, 
					autoShowLoading:true,
					textLoading: '玩命加载中...',
					textSuccess: "刷新成功",
				},
				upOption:{
					auto:false,
					noMoreSize: 4, 
					empty:{
						tip: '~ 搜索无数据 ~',
						btnText: ''
					},
					textLoading: "玩命加载中...",
					textNoMore: "-- 人家是有底线的 --",
				}
			}
		},
		onLoad(option){
			//更新app图标红点
			this.$redpoint(option);
		},
		watch:{
			giftlist(){
				setTimeout(() => {
					this.globelloading = false;
				}, 800)	
			}
		},
		methods:{
			downCallback(){
				// console.log('downCallback')
				this.mescroll.resetUpScroll()
			},
			upCallback(page){
				// console.log('upCallback')
				// console.log(page.num);
				this.getinitdata(page.num).then(res => {
					// console.log(res);
					this.mescroll.endSuccess(res.length);
					//设置列表数据
					if (page.num == 1) this.giftlist = [] //如果是第一页需手动制空列表
					this.giftlist = this.giftlist.concat(res) //追加新数据
				}).catch(error => {
					this.mescroll.endErr()
					this.$ShowMsg('error::'+JSON.stringify(error))
				})
			},
			getinitdata(page) {
				return new Promise((resolve, reject) => {
					this.$HttRequest({
						url: '/lottery/redLottery',
						param: {page:page}
					}).then((res) => {
						//console.log(res)
						if (res.status === 10000) {
							resolve(res.data.data);
						} else {
							this.$ShowMsg(res.message);
						}
					}).catch((error) => {
						//异常错误
						reject(error.errMsg);
					})
				})
			}
		}
	}
</script>

<style lang="scss">
	
</style>
